package com.heima.article.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.heima.model.article.dtos.ArticleHomeDTO;
import com.heima.model.article.pojos.ApArticle;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.SimpleTimeZone;

@Mapper
public interface ApArticleMapper extends BaseMapper<ApArticle> {
    /**
     * 查询文章列表
     *
     * @param dto
     * @param type 0：加载更多   1：加载最新
     * @return
     */
    public List<ApArticle> loadArticleList(@Param("dto") ArticleHomeDTO dto, @Param("type") Short type);


    @Select("select aa.* from ap_article aa left join ap_article_config aac on aa.id=aac.article_id " +
            "where aac.is_delete!=1 and aac.is_down != 1 " +
            "and aa.publish_time >= #{beginDate}")
    public List<ApArticle> selectArticleByDate(@Param("beginDate") String beginDate);

    /**
     * 远程调用 查询范围内的时间信息
     * @param preTime
     * @param beTime
     * @return
     */
    @Select("select * from ap_article\n" +
            "where publish_time >= #{preTime} AND publish_time <= #{beTime}")
    public List<ApArticle> selectArticleList(@Param("preTime") String preTime,@Param("beTime")String beTime);

    Map<String, Integer> statisticsNews(@Param("stime") Date stime, @Param("etime") Date etime, @Param("authorId") String authorId);

    //统计时间段内每天的
    List<Map<String, Object>> statisticsNewsByDay(@Param("stime") Date stime, @Param("etime") Date etime, @Param("authorId") String authorId);
    //根据日期和作者id查询所有文章
    List<ApArticle> statisticsNewsByDate(@Param("date") String date,@Param("authorId") String authorId);

}
